package com.cytech.cloudclinic.moudle.main.patient.detail.base;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.base.BaseFragment;
import com.cytech.cloudclinic.bean.Patient;
import com.cytech.cloudclinic.moudle.main.patient.detail.PatientDetailPresenter;
import com.cytech.cloudclinic.moudle.main.patient.detail.PatientDetailView;
import com.cytech.cloudclinic.utils.TimeUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class PatientDetailBaseFragment extends BaseFragment<PatientDetailPresenter> implements PatientDetailView {

    @BindView(R.id.et_patient_detail_name)
    EditText etPatientDetailName;
    @BindView(R.id.et_patient_detail_sex)
    EditText etPatientDetailSex;
    @BindView(R.id.tv_patient_detail_birthday)
    TextView tvPatientDetailBirthday;
    @BindView(R.id.et_patient_detail_age)
    EditText etPatientDetailAge;
    @BindView(R.id.et_patient_detail_phone)
    EditText etPatientDetailPhone;
    @BindView(R.id.et_patient_detail_address)
    EditText etPatientDetailAddress;
    @BindView(R.id.et_patient_detail_history)
    EditText etPatientDetailHistory;
    @BindView(R.id.et_patient_detail_allergy_history)
    EditText etPatientDetailAllergyHistory;
    private int patientId = 0;

    public static PatientDetailBaseFragment newInstance(int patientId) {
        PatientDetailBaseFragment fragment = new PatientDetailBaseFragment();
        //如果有参数，使用Bundle传递
        Bundle bundle = new Bundle();
        bundle.putInt("patientId", patientId);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    protected PatientDetailPresenter createPresenter() {
        return new PatientDetailPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_patient_detail_base;
    }

    @Override
    protected void initView() {

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    protected void initData() {
        patientId = getArguments().getInt("patientId");
        presenter.getPatientDetail(patientId);
    }

    @Override
    public void getPatientDetailSuccess(Patient patient) {
        etPatientDetailName.setText(patient.name);
        etPatientDetailSex.setText(patient.getGender());
        tvPatientDetailBirthday.setText(patient.birthday);
        if(!TextUtils.isEmpty(patient.birthday)){
            etPatientDetailAge.setText(TimeUtils.getAgeDetail(patient.birthday));
        }
        etPatientDetailPhone.setText(patient.phone);
        etPatientDetailAddress.setText(patient.address);
    }

    @OnClick(R.id.btn_update_patient)
    public void onViewClicked() {

    }
}
